/*
 * @Author: silas 
 * @Date: 2021-03-10 16:18:01 
 * @Last Modified by: silas
 * @Last Modified time: 2021-04-30 19:08:27
 */

<template>
    <div class="clearing">
        <div class="">
            <div class="fr" v-if="id">
                <el-button
                    @click="$router.push({ path: '/budget/circleTabs' })"
                    size="mini"
                    >返回</el-button
                >
            </div>
        </div>
        <p class="g-unit">单位: 万元</p>
        <div class="tableBox">
            <el-table
                id="table1"
                ref="table"
                size="mini"
                :header-cell-style="{ background: '#eef1f6' }"
                :data="tableData"
                v-loading="tableLoading"
                style="width: 100%"
                border
            >
                <el-table-column prop="areaName" label="分公司" width="120" />
                <el-table-column
                    v-for="(it, i) in titles"
                    min-width="120"
                    :key="i"
                    :label="it"
                    :prop="'codeIdValue' + i"
                ></el-table-column>
            </el-table>
        </div>
    </div>
</template>

<script>
import { $budgetAPI } from "@/api/";
import { getSessionStorage } from "@/common/js/storage";
import prefixAPI from "@/api/prefixAPI";
import { getCookie } from "@/common/js/cookie";
import FileSaver from "file-saver";
import XLSX from "xlsx";

export default {
    name: "clearing-tab2",
    data() {
        return {
            accountInfo: "",
            form: {
                areaId: "",
                year: "",
            },
            tableLoading: false,
            tableData: [],
            titles: [],
            id: "",
        };
    },
    mounted() {
        var that = this,
                id = that.$route.query.id;

            that.id = id;
            if (!id) {
                that.accountInfo = JSON.parse(getSessionStorage("accountInfo"));
                that.form.areaId = that.accountInfo.areaId;
                that.form.year = that.moment().format("YYYY");
            }
            that.getData(id);
    },
    methods: {
        init() {
            
        },
        getData(id) {
            var that = this,
                titles = [];

            that.tableLoading = true;
            $budgetAPI.getCircleDetail(
                {
                    areaId: that.form.areaId,
                    acctYear: that.form.year,
                    token: getCookie("token"),
                    recordId: id,
                },
                (res) => {
                    console.log(res);
                    if (res.code == 0) {
                        res.content.data.map((it, i) => {
                            it.dataList.map((item, index) => {
                                it["codeIdValue" + index] = item.codeIdValue;
                            });
                        });
                        res.content.titles.map((it) => {
                            titles.push(it.specialName);
                        });
                        that.tableData = res.content.data;
                        that.titles = titles;
                    }
                    that.tableLoading = false;
                }
            );
        },
    },
};
</script>

<style lang="scss" scoped>
</style>